export const resize = {
  data() {
    return {
      timer: null,
    }
  },
  mounted() {
    window.addEventListener("resize", this.debounce);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.debounce);
  },
  methods: {
    async resizeChart() {
      if (this.myChart == null) { return };
      await this.$nextTick();
      this.myChart.resize();
    },
    debounce() {
      if (this.timer) {
        clearTimeout(this.timer);
      }
      this.timer = setTimeout(() => {
        this.timer = null;
        this.resizeChart();
      }, 500);
    }
  },
}